package me.zhengjie.modules.readfile.service.impl;

import me.zhengjie.modules.readfile.service.FileService;
import me.zhengjie.modules.utils.DocToPDF;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;

@Service
public class FileServiceImpl implements FileService {


    @Value("${file.windows.path}")
    private String pathFile;

    @Override
    public Boolean returnPDF(String path){



        path = path.replace("/file","");
        String filePath = this.pathFile + path.replace("/","\\");

        if (!new File(filePath).exists()){
            return false;
        }


        String pdfFilePath = filePath.substring(0,filePath.lastIndexOf("."))+".pdf";
        if (new File(pdfFilePath).exists()){
            return true;
        }

        try {
            DocToPDF.wordConverterToPdf(filePath,pdfFilePath);
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
        return true;
    }

}
